import axios from "axios";
import { ElMessage } from "element-plus";
import router from "../router";
const request = axios.create({
  baseURL: '/api',
  timeout: 60000000,
});
request.interceptors.request.use(
(config)=>{
let loginInfo=JSON.parse(localStorage.getItem('loginInfo'))
if(loginInfo!=null){
  config.headers.token=loginInfo.token
}
return config
}
)

request.interceptors.response.use(
(response) => { 
return response.data
},
(error) => {
if(error.response.status==401){
  ElMessage.error("登录失效，请重新登录")
  router.push('/login')
}
return Promise.reject(error)
}
)
export default request